/**
 * 1
 *  
 * @Author : roryrywang
 * @DateTime : 24-9-9 下午6:48
 */

#include <algorithm>
#include <iostream>
#include <vector>
#include <unordered_set>

using namespace std;

const int MOD = 1e9 + 7;

int main() {
    int n;
    cin >> n;
    int lmin = 510;
    int lcnt = 0;
    int rmax = -1;
    int rcnt = 0;
    unordered_set<int> set;
    for (int i = 0; i < n; i++) {
        int l, r;
        cin >> l >> r;
        for (int j = l + 1; j < r; ++j) {
            set.insert(j);
        }
        if (l < lmin) {
            lmin = l;
            lcnt = 1;
        } else if (l == lmin) {
            lcnt++;
        }
        if (r > rmax) {
            rmax = r;
            rcnt = 1;
        } else if (r == rmax) {
            rcnt++;
        }
    }

    if (lcnt % 2) {
        set.insert(lmin);
    }
    if (rcnt % 2) {
        set.insert(rmax);
    }

    long long tmp = 1;
    long long res = 0;

    for (int i = 0; i <= rmax; i++) {
        if (set.count(i)) {
            res = (res + tmp) % MOD;
        }
        tmp = (tmp * 2) % MOD;
    }

    cout << res;

    return 0;
}